/**
 * 
 */
package co.edu.eam.iso.view.treetable;

import co.edu.eam.iso.enums.RankEnum;
import co.edu.eam.iso.evaluated.CharacteristicEvaluated;
import co.edu.eam.iso.evaluated.MetricEvaluated;
import co.edu.eam.iso.evaluated.ProductEvaluated;
import co.edu.eam.iso.evaluated.SubCharacteristicEvaluated;

/**
 * @author Giovanny Ramirez Blandon
 * @version 1.0
 */
public class Node {

	private Object node;
	private Object[] children;

	public Node(Object node) {
		this.node = node;
	}

	public Object[] getChildren() {
		if (node instanceof ProductEvaluated) {
			ProductEvaluated pe = (ProductEvaluated) node;
			children = pe.getCharacteristics().values().toArray();
		}

		if (node instanceof CharacteristicEvaluated) {
			CharacteristicEvaluated ce = (CharacteristicEvaluated) node;
			children = ce.getSubCharacteristics().values().toArray();
		}

		if (node instanceof SubCharacteristicEvaluated) {
			SubCharacteristicEvaluated se = (SubCharacteristicEvaluated) node;
			children = se.getMetrics().toArray();
		}

		return children;
	}

	public String getInfo(int column) {
		if (node instanceof ProductEvaluated) {
			ProductEvaluated pe = (ProductEvaluated) node;
			switch (column) {
			case 0:
				return "Calidad del producto " + pe.getQuality() + "%";
			case 1:
				return RankEnum.determinateRank(pe.getQuality()).toString();
			case 2:
				return pe.getQuality().toString();
			}
		}

		if (node instanceof CharacteristicEvaluated) {
			CharacteristicEvaluated ce = (CharacteristicEvaluated) node;
			switch (column) {
			case 0:
				return ce.getCharacteristic().getCharacteristicEnum().name();
			case 1:
				return RankEnum.determinateRank(ce.getQuality()).toString();
			case 2:
				return ce.getQuality().toString();
			}
		}

		if (node instanceof SubCharacteristicEvaluated) {
			SubCharacteristicEvaluated se = (SubCharacteristicEvaluated) node;
			switch (column) {
			case 0:
				return se.getSubCharacteristic().getSubCharacteristicEnum()
						.name();
			case 1:
				return "";
			case 2:
				return se.getQuality().toString();
			}
		}

		if (node instanceof MetricEvaluated) {
			MetricEvaluated me = (MetricEvaluated) node;
			switch (column) {
			case 0:
				return me.getMetric().getDescription();
			case 1:
				return me.getMetric().getScale().toString();
			case 2:
				return me.getQuality().toString();
			}
		}

		return null;
	}

}
